//
//  XJStatusRetweetView.swift
//  XJWeiBO
//
//  Created by 452608533 on 16/7/24.
//  Copyright © 2016年 452608533. All rights reserved.
//

import UIKit
import SnapKit
class XJStatusRetweetView: UIView {

    var retweetViewBottomConstranit:Constraint?
    
    var statusViewModel: XJStatusViewModel?{
        didSet{
            contentLabel.text = statusViewModel?.status?.retweeted_status?.text
            
            //卸载约束
            retweetViewBottomConstranit?.uninstall()
            
            if statusViewModel?.status?.retweeted_status?.pic_urls?.count > 0{
                //代表有配图
                pictureView.pictureInfo = statusViewModel?.status?.retweeted_status?.pic_urls
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.retweetViewBottomConstranit = make.bottom.equalTo(pictureView).offset(10).constraint
                })
               pictureView.hidden = false
            }else{
                //没有配图
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.retweetViewBottomConstranit = make.bottom.equalTo(contentLabel).offset(10).constraint
                })
                pictureView.hidden = true
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        backgroundColor = UIColor.whiteColor()
        addSubview(contentLabel)
        addSubview(pictureView)
        contentLabel.preferredMaxLayoutWidth = SCREENW - 20
        contentLabel.numberOfLines = 0
        contentLabel.font = UIFont.systemFontOfSize(15)
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.leading.equalTo(10)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
            make.leading.equalTo((SCREENW - (cellWH*3 + cellMargin*2))/2)
        }
        //约束当前的view
        self.snp_makeConstraints { (make) -> Void in
//            make.bottom.equalTo(contentLabel).offset(10)
            self.retweetViewBottomConstranit = make.bottom.equalTo(pictureView).offset(10).constraint
        }
        
    }
    
    private lazy var contentLabel: UILabel = UILabel()
    private lazy var pictureView:XJStatusPictureView = XJStatusPictureView()

}
